package com.itqf.mybatis;

import com.itqf.bean.DtsAdmin;
import com.itqf.bean.DtsAdminExample;
import com.itqf.mapper.DtsAdminMapper;
import com.itqf.utils.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * projectName: mybatisgp8
 *
 * @author: 赵伟风
 * time: 2021/8/16 16:44
 * description:
 */
public class UseMyBatis {


    public static void main(String[] args) {

        SqlSession sqlSession = MyBatisUtils.openSession();

        DtsAdminMapper mapper = sqlSession.getMapper(DtsAdminMapper.class);

       // DtsAdmin dtsAdmin = mapper.selectByPrimaryKey(5);

        /**
         * 查询 id = 5 或者 id 等于 7  并且 username like admin
         *
         */

//          DtsAdminExample dtsAdminExample = new DtsAdminExample();
//
//        DtsAdminExample.Criteria criteria = dtsAdminExample.createCriteria();
//
//
//        List<Integer> ids = new ArrayList<>();
//
//        ids.add(5);
//        ids.add(7);
//
//        criteria.andIdIn(ids);
//        criteria.andUsernameLike("%admin%");


        /**
         * id = 7 or username = admin
         */


        DtsAdminExample example = new DtsAdminExample();

        DtsAdminExample.Criteria criteria = example.createCriteria();
        criteria.andIdEqualTo(5);


        DtsAdminExample.Criteria criteria1 = example.or();
        criteria1.andUsernameEqualTo("admin");


        List<DtsAdmin> admins = mapper.selectByExample(example);

        System.out.println("admins = " + admins);

        sqlSession.close();


    }

}
